﻿using Elasticsearch.Net;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Nest;

namespace VisionCloud.Utility.ElasticSearch
{
    public static class ElasticSearchExtensions
    {
        /// <summary>
        /// 注入elasticservice服务
        /// </summary>
        /// <param name="services"></param>
        /// <param name="configuration"></param>
        /// <returns></returns>
        public static IServiceCollection AddElasticService(this IServiceCollection services, IConfiguration configuration)
        {
            services.Configure<ElasticSearchConfig>(configuration.GetSection("NLog"));
            services.AddSingleton<IConnectionPool, ElasticSearchConnectPool>();
            services.AddSingleton<IElasticClient, DefaultElasticClient>();
            return services;
        }
    }
}